package com.example.lx5_27.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.base.entity.VisitEntityItem
import com.example.lx5_27.R
import com.example.lx5_27.databinding.ItemVisitBinding

class VisitAdapter : PagingDataAdapter<VisitEntityItem,VisitAdapter.VisitViewHolder>(diff) {

    companion object{
        val diff = object : ItemCallback<VisitEntityItem>() {
            override fun areItemsTheSame(
                oldItem: VisitEntityItem,
                newItem: VisitEntityItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: VisitEntityItem,
                newItem: VisitEntityItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }

    class VisitViewHolder(view:View) : ViewHolder(view){
        val binding = DataBindingUtil.bind<ItemVisitBinding>(view)
    }

    override fun onBindViewHolder(holder: VisitViewHolder, position: Int) {
        holder.binding?.vis = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VisitViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_visit, parent, false)
        return VisitViewHolder(view)
    }


}